
#include <deque>

class CANDriver
{
public:
	bool Init(int divider, int deviceType, int serial);
	bool ReadDataFullCAN(int index, char* buffer); // read Full CAN messages
	bool ReadData(int CANNr, char* buffer, int& id);
	void GetErrorCounters(int CANNr, int& TEC, int& REC);

	// high level API
	void Update();
	bool BufferDataCAN(int canNr, bool extended, unsigned int ID, char* buffer);

private:
	// low level API
	bool SendDataCAN1(bool extended, unsigned int ID, char* buffer );
	bool SendDataCAN2(bool extended, unsigned int ID, char* buffer );

private:
	struct SCANPacket
	{
		bool extended;
		unsigned int ID;
		char buffer[8];
	};

	std::deque<SCANPacket> m_CAN1PacketList;
	std::deque<SCANPacket> m_CAN2PacketList;

	// busoff states
	bool m_IsInRecovery[4];
};

struct FULLCanID
{
	int CANCtrl; // 0-CAN1, 1-CAN2, 2-CAN3, 3-CAN4
	unsigned int ID; // 11-bit ID
	bool enabled; // true - enabled
	bool generateInt; // true - generates interrupt
};

struct ExtendedCanID
{
	int CANCtrl; // 0-CAN1, 1-CAN2, 2-CAN3, 3-CAN4
	unsigned int ID; // 29-bit ID
};
